Specification and Automatic Prototype Implementation of Polymorphic Objects in TURING Using the TXL Dialect Processor

نویسندگان

  • James R. Cordy
  • Eric Promislow
چکیده

Object-oriented dialects of existing programming languages are often implemented using a preprocessor that translates from the dialect to an equivalent program in the original programming language. Unfortunately, the nature of the preprocessing done by these implementations is hidden in the ad-hoc algorithms of the preprocessors themselves except as demonstrated by examples. This paper describes an attempt to catalogue and generalize these syntactic transformations using a simple set of applicative transformation rules expressed in the TXL dialect description language. Example transformation rules for implementing object types and parametric polymorphism in an object-oriented dialect of the Turing programming language are given in the paper. These rules easily generalize to other languages of the Pascal family and have been used to automatically implement Objective Turing. Introduction Object-oriented dialects of existing programming languages such as C are commonly prototyped using a preprocessor that translates from the object-oriented dialect to the base language. This was the case, for example, for C++ [l] and Objective C [2]. However, the nature of the preprocessing done by these implementations is often hidden in the ad-hoc algorithms of the preprocessors themselves, and is at best exposed by a few simple examples of the results of the preprocessing. The Objective Turing project is an attempt to rectify this situation by explicitly specifying each key feature of object-oriented programming as a context-sensitive syntactic transform to the (non-objective) Turing programming language 131 using the TXL dialect specification language [4]. By specifying each feature using an independent TXL transformation rule which clearly and compactly encodes the necessary syntactic transforms, we can compile a reference catalog for preprocessor implementation of object-oriented features that can be used to guide future preprocessor implementations for other languages. This paper introduces the TXL dialect specification language and gives a complete set of applicative transformation rules to implement polymorphic object types as a dialect of Turing. These rules have been used to automatically implement Objective TURING using the TXL dialect processor. The TXL Dialect Processor TXL, the Turing extender Language [4] is a system designed to allow easy description and automatic prototype implementation of new programming language features as dialects of an existing programming language such as Turing. The goal of TXL is to provide some measure of the power and flexibility of interpretive extensible languages for traditional Pascal-like compiled languages. TXL uses a context-sensitive syntactic transformation algorithm that is not limited by the constraints typical of other preprocessors and extensible languages, and is driven by a concise, readable dialect specification language that conveniently expresses the syntax and semantics of new language features. Using Turing (or any other language) as a base, TXL provides the ability to describe new language dialects at a very high level, and automatically provides prototype implementations. Each dialect is described in two parts, the context-free syntactic forms (described in terms of the syntactic forms of the base language using a BNF-like notation), and the run time model of the dialect (expressed as a set of applicative syntactic transformations to the base language). The TXL Processor uses these descriptions to automatically transform dialect programs to programs in the base language. This work was supported by Ute Natural Sciences and Engineering Research Council of Canada CH2854-8/90/oooO/0145$01.W @ 1990 IEEE I45 The syntactic forms of the base language are described using the same BNF-like notation used to describe syntactic forms of the dialect. These base language syntactic forms serve as a data base of syntactic forms used to describe the syntax of the dialect. For example, the syntactic forms of the Turing language base include the forms deckrationsAndStatements, VariableReference, assignment, and so on. The semantics of the dialect are described as a set of recursive contextsensitive transformations from the syntactic structures of the dialect to base language structures. As a simple example dialect, consider the addition of coalesced assignment short forms (i.e., the m+=", etc. of C) to the Turing language. The desired syntactic forms can be described in terms of the Turing base forms as a replacement of the statement syntactic form to include the original Turing statements plus a new form we call coalescedAss@nment (Figure 1). The new definition of the statement syntactic form replaces the original Turing form in the grammar of the dialect, so that the dialect includes all of original Turing plus the new coalesced assignment statement. The form of the coalesced assignments themselves is described using the new syntactic form coalescedAssgnment and its sub-form coales&Qwrator. The meaning of the new syntactic form is described using a transformation to equivalent Turing base language code. In this case, for example, the transformation rule would change the coalesced assignment a += b to the semantically equivalent Turing statement a := a + (b). Transformation is achieved by applying the transformation rules to the abstract syntax tree of each dialect language program. For example, the main transformation rule of the coalesced assignment dialect (figure 1) specifies that in each subtree below a statement node, any subtree matching the pattern VariableReference coalescedOperator = expression should be replaced by another statement subtree containing the assignment statement V := V Op (E) where V, Op and E are the original subtrees for the VariableReference, coalescedOperator and expression matched by the pattern. Objective TURING Turing [3] is a new general purpose programming language in the tradition of Pascal. In addition to the features provided by Pascal, Turing provides other modem programming features such as encapsulation using modules, varying-length character strings, typesafe variant records, safe dynamic storage and pointers, parametric procedures, and run-time constants. Turing does not however provide any object-oriented features such as object types, polymorphism, inheritance or dynamic binding. 146 % Trivial coalesced assignment dialect; % allows a += b etc. % Part 1: Syntactic forms deflne statement % replaces Turing base % syntactic form of same name [coalescedkignment] 56 new dialect % statement form [assignment] % original Turing [a=dI % statement forms choose ... bet1 end define def I ne coalesced Assig nme nt order [variableReference] [coalescedOperator] = [expression] end define deflne coalescedoperator end deflne Choose + I % Part 2: Semantic transformations rule replaceCoalescedOperators taplace [statement] by [statement] V [variableReference] Op [coalescedOperator] = E [expression] V := V Op ( E ) end rule Figure 1. TXL Description of a Simple Coalesced Assignment Dialect. In Part 1, the syntactic forms of the dialect are described using a BNF-like notation in which the keyword cuder indicates sequence and the keyword chuose indicates alternation. The dialect syntactic forms are integrated into the base language grammar by replacing an existing base language syntactic form with a new form. In the above example, the new form of statement replaces the original Turing syntactic form of the same name in the dialect grammar. In Part 2, the semantics of the dialect are described using a set of rules that transform the syntactk forms of the dialect to semantically equivalent base language structures. In this case, every occurrence of a statement containing the dialect syntactic form coalescedoperator is transformed to an assignment statement using the comsponding Turing operator. Modules and Information Hiding One feature of object-oriented systems that the Turing language already provides is information hiding in the form of modules. Turing modules collect a set of data structures and the procedures that manipulate them into a single opaque package. Only the exported attributes of the module can be accessed from outside it. From an object-oriented point of view. a Turing module is a single instance object, and its exported procedures are the methods of the object. Figure 2 shows an example of a Turing stack module. Although we will use them as a vehicle to implement object types in this paper, modules are not a prerequisite for the transformations presented. Because the information hiding provided by modules can itself be expressed as a syntactic transform to procedures and records [5], our transformations are easily extended to apply to languages without modules such as Pascal. module stack import (error) export (push, pop) const maxdepth := 100 var storage : array 1 .. maxdepth of Int var depth : 0 .. maxdepth procedure push (e : Int) If depth <= maxdepth then storage (depth) := e eke error (“stack overflow”) end If end push procedure pop (var e : Int) e := storage (depth) error (“stack underflow”) depth := depth + 1

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

An automatic test case generator for evaluating implementation of access control policies

One of the main requirements for providing software security is the enforcement of access control policies which aim to protect resources of the system against unauthorized accesses. Any error in the implementation of such policies may lead to undesirable outcomes. For testing the implementation of access control policies, it is preferred to use automated methods which are faster and more relia...

متن کامل

A Practical Evaluation of Using TXL for Model Transformation

As one of the MDA’s main principles, model transformation has led to the specification of QVT and a large number of model transformation tools. TXL is a generic source transformation tool that also possesses some very important model transformation properties, such as scalability and efficiency. In this paper, we consider TXL as a model transformation tool, especially, for model-to-model transf...

متن کامل

Kohonen Self Organizing for Automatic Identification of Cartographic Objects

Automatic identification and localization of cartographic objects in aerial and satellite images have gained increasing attention in recent years in digital photogrammetry and remote sensing. Although the automatic extraction of man made objects in essence is still an unresolved issue, the man made objects can be extracted from aerial photos and satellite images. Recently, the high-resolution s...

متن کامل

TXL: a rapid prototyping system for programming language dialects

This paper describes a rapid prototyping system for extensions to an existing programming language. Such extensions might include new language features or might introduce notation specific to a particular problem domain. The system consists of a dialect description language used to specify the syntax and semantics of extensions, and a context sensitive syntactic transducer that automatically im...

متن کامل

Design and Implementation of Field Programmable Gate Array Based Baseband Processor for Passive Radio Frequency Identification Tag (TECHNICAL NOTE)

In this paper, an Ultra High Frequency (UHF) base band processor for a passive tag is presented. It proposes a Radio Frequency Identification (RFID) tag digital base band architecture which is compatible with the EPC C C2/ISO18000-6B protocol. Several design approaches such as clock gating technique, clock strobe design and clock management are used. In order to reduce the area Decimal Matrix C...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1990